'''
作者:lrh
时间:2023/9/24 12:10
内容:封装机器人
'''
import datetime
import requests

headers = {'Content-Type': 'application/json'}
# 机器人的webhook地址
urlw = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=4a4555b1-7c5d-4145-b615-c78be2803e47'


class Robot:

    def message(self, project_name, url, total, passed, failed, skipped, bili, adress):
        time = datetime.datetime.now()
        data = {
            "msgtype": "markdown",
            "markdown": {
                "content":
                    '''<font color=\"warning\">接口自动化测试反馈\n请相关同事注意，及时跟进！</font>\n
                    > 执行时间: {}\n
                    > 项目名称: {}\n
                    > 环境: {}\n
                    > 总数: <font color=\"info\">{}</font> 个\n
                    > 通过数: <font color=\"info\">{}</font> 个\n
                    > 失败数: <font color=\"warning\">{}</font> 个\n
                    > 跳过数: <font color=\"warning\">{}</font> 个\n
                    > 通过率: <font color=\"info\">{}</font> \n
                    > 报告链接：[详细测试报告,请连接VPN后进入查看]({})
                '''.format(time, project_name, url, total, passed, failed, skipped, bili, adress)
            }
        }
        return data

    def sendMessage(self, project_name, url, total, passed, failed, skipped, bili, adress):
        data = self.message(project_name, url, total, passed, failed, skipped, bili, adress)

        requests.post(url=urlw, headers=headers, json=data)
        print('发消息了')
